package com.example.rlw.mvpplugintest.login;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.example.rlw.mvpplugintest.R;
import com.example.rlw.mvpplugintest.bean.UserBean;
import com.example.rlw.mvpplugintest.home.HomeActivity;
import com.example.rlw.mvpplugintest.mvp.MVPBaseActivity;
import com.kingja.loadsir.callback.Callback;

import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;


public class LoginActivity extends MVPBaseActivity<LoginContract.View, LoginPresenter> implements LoginContract.View, Callback.OnReloadListener {

    @BindView(R.id.username)
    EditText mUsername;
    @BindView(R.id.userpwd)
    EditText mUserpwd;
    @BindView(R.id.login)
    Button mLogin;
    @BindView(R.id.ll_title_back)
    LinearLayout mLlTitleBack;
    @BindView(R.id.tv_title_title)
    TextView mTvTitleTitle;

    @Override
    public void loginSuccess(List<UserBean> user) {
        Toast.makeText(this, "登录成功", Toast.LENGTH_SHORT).show();
        openActivity(HomeActivity.class);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.login_layout;
    }

    @Override
    protected void initView() {
        mTvTitleTitle.setText("登录界面");
        mLlTitleBack.setVisibility(View.GONE);
    }

    @Override
    protected void initData(@Nullable Bundle savedInstanceState) {
    }

    @Override
    protected void initNet() {

    }

    @OnClick(R.id.login)
    public void onClickView(View view) {
        showLoadingView();
        login();
    }

    private void login() {
        String userName = mUsername.getText().toString().trim();
        String userPwd = mUserpwd.getText().toString().trim();
        mPresenter.login(userName, userPwd);
    }

    @Override
    public void onReload(View v) {
        login();
    }
}
